package com.gitee.feizns.webtemplate.commons.data.page;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.gitee.feizns.webtemplate.commons.data.order.OrderBy;
import com.gitee.feizns.webtemplate.commons.data.order.OrderColumn;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author feizns
 * @since 2019/5/12 0012
 */
public class OrderPagination extends Pagination implements OrderBy, IPage {

    /**
     * 用来保存起始位置，
     */
    @Getter
    @Setter
    private int start;

    public OrderPagination(int current, int size) {
        super(current, size);
    }

    public OrderPagination(int current, int size, OrderColumn... orderColumns) {
        super(current, size);
        this.orderColumns = Arrays.asList(orderColumns);
    }

    /**
     * 排序字段
     */
    private List<OrderColumn> orderColumns;

    @Override
    public List<OrderColumn> orderBy() {
        return orderColumns == null ? Collections.emptyList() : orderColumns;
    }

    @Override
    public Integer getBeginPos() {
        return getStart();
    }

    @Override
    public Integer getCurtPage() {
        return getCurrent();
    }

    @Override
    public Integer getPageSize() {
        return getSize();
    }

    @Override
    public Long getPageCount() {
        return getPages();
    }

}
